package com.zsc.shixun.controller;

import com.zsc.shixun.common.CommonResult;
import com.zsc.shixun.common.ResultUtil;
import com.zsc.shixun.model.message.MessageVo;
import com.zsc.shixun.service.IMessageService;
import com.zsc.shixun.utils.LoginMessageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author ZWYZY
 * @since 2021/4/17
 */
@Validated
@Controller
@RequestMapping("/message")
public class MessageController {
    @Autowired
    private LoginMessageUtils loginMessageUtils;
    @Autowired
    private IMessageService messageService;
    @GetMapping("/getMessageList")
    @ResponseBody
    public CommonResult getMessageList(){
        List<MessageVo> messageVoList = messageService.getMessageListByUserId(loginMessageUtils.getMessage().getLoginUser().getId());
        return ResultUtil.success(messageVoList);
    }

    @PostMapping("/updateMessageDelete")
    @ResponseBody
    public CommonResult updateMessageDelete(){
        messageService.updateAllDelete(loginMessageUtils.getMessage().getLoginUser().getId(),true);
        return ResultUtil.success();
    }

    @PostMapping("/updateByUserIdMessage")
    @ResponseBody
    public CommonResult updateByUserIdMessage(@RequestParam Long id){
        messageService.updateDeleteById(id);
        return ResultUtil.success();
    }
}
